﻿namespace Snipps.Views
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;

    public partial class FilterView : UserControl
    {
        public FilterView()
        {
            InitializeComponent();
            snippetDetailsControl.IsVisibleChanged += snippetDetailsControl_IsVisibleChanged;
            SetRow2Height();
        }

        private void snippetDetailsControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            SetRow2Height();
            if (!snippetDetailsControl.IsVisible && snippetDetailsControl.IsFocused)
            {
                var request = new TraversalRequest(FocusNavigationDirection.Next) { Wrapped = true };
                snippetDetailsControl.MoveFocus(request);
            }
        }

        private void SetRow2Height()
        {
            if (snippetDetailsControl.Visibility == Visibility.Visible)
            {
                row2.Height = new GridLength(2.0, GridUnitType.Star);
            }
            else
            {
                row2.Height = new GridLength(0);
            }
        }
    }
}